
Public Class CorreoElectronico
    Public Shared Sub EnvioCorreoHTML(ByVal url As String, ByVal destino As String, ByVal remitente As String, ByVal asunto As String, ByVal servidor As String, Optional ByVal usuario As String = "", Optional ByVal contrasena As String = "", Optional ByVal arrStrRutaAttachments As ArrayList = Nothing, Optional ByVal prioridadDeCorreo As Net.Mail.MailPriority = Net.Mail.MailPriority.Normal, Optional ByVal requiereAutenticacion As Boolean = False)
        Dim m As New System.Web.Mail.MailMessage
        Dim wr As Net.WebRequest = Net.WebRequest.Create(url)
        Dim wResponse As Net.WebResponse = wr.GetResponse()
        Dim s As IO.Stream = wResponse.GetResponseStream
        Dim sr As New IO.StreamReader(s)
        m.Body = sr.ReadToEnd
        s.Close()

        'M.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver"); = "smtpserver" 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport"); = 25 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing"); = 2 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"); = 1 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername"); = "username" 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword"); = "password" 

        If Not IsNothing(arrStrRutaAttachments) AndAlso arrStrRutaAttachments.Count > 0 Then
            Dim strRuta As String
            For Each strRuta In arrStrRutaAttachments
                Dim oAttch As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment(strRuta)
                m.Attachments.Add(oAttch)
            Next
        End If
        m.Priority = prioridadDeCorreo

        m.From = remitente
        m.Subject = asunto
        m.BodyFormat = Web.Mail.MailFormat.Html
        'm.To = r.email
        m.To = destino
        System.Web.Mail.SmtpMail.SmtpServer = servidor
        System.Web.Mail.SmtpMail.Send(m)

        'Dim smtp As New System.Net.Mail.SmtpClient
        'smtp.Host = "servidor de correo"

    End Sub

    Public Shared Sub EnvioCorreo(ByVal cuerpoHTML As String, ByVal destino As String, ByVal remitente As String, ByVal asunto As String, ByVal servidor As String, Optional ByVal usuario As String = "", Optional ByVal contrasena As String = "", Optional ByVal arrStrRutaAttachments As ArrayList = Nothing, Optional ByVal prioridadDeCorreo As Net.Mail.MailPriority = Net.Mail.MailPriority.Normal, Optional ByVal requiereAutenticacion As Boolean = False)
        Dim m As New System.Web.Mail.MailMessage

        If Not IsNothing(arrStrRutaAttachments) AndAlso arrStrRutaAttachments.Count > 0 Then
            Dim strRuta As String
            For Each strRuta In arrStrRutaAttachments
                Dim oAttch As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment(strRuta)
                m.Attachments.Add(oAttch)
            Next
        End If
        m.Priority = prioridadDeCorreo

        m.From = remitente
        m.Subject = asunto
        m.BodyFormat = Web.Mail.MailFormat.Html
        m.To = destino
        m.Body = cuerpoHTML
        System.Web.Mail.SmtpMail.SmtpServer = servidor
        System.Web.Mail.SmtpMail.Send(m)

    End Sub

    Public Shared Sub EnvioCorreoHTMLNuevo(ByVal url As String, ByVal destino As String, ByVal remitente As String, ByVal asunto As String, ByVal servidor As String, Optional ByVal usuario As String = "", Optional ByVal contrasena As String = "", Optional ByVal arrStrRutaAttachments As ArrayList = Nothing, Optional ByVal prioridadDeCorreo As Net.Mail.MailPriority = Net.Mail.MailPriority.Normal, Optional ByVal requiereAutenticacion As Boolean = False)
        Dim m As New Net.Mail.MailMessage
        Dim wr As Net.WebRequest = Net.WebRequest.Create(url)
        Dim wResponse As Net.WebResponse = wr.GetResponse()
        Dim s As IO.Stream = wResponse.GetResponseStream
        Dim sr As New IO.StreamReader(s)
        m.Body = sr.ReadToEnd
        s.Close()

        'M.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver"); = "smtpserver" 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport"); = 25 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing"); = 2 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"); = 1 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername"); = "username" 
        'Msg.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword"); = "password" 

        'If Not IsNothing(arrStrRutaAttachments) AndAlso arrStrRutaAttachments.Count > 0 Then
        '    Dim strRuta As String
        '    For Each strRuta In arrStrRutaAttachments
        '        Dim oAttch As System.Web.Mail.MailAttachment = New System.Web.Mail.MailAttachment(strRuta)
        '        m.Attachments.Add(oAttch)
        '    Next
        'End If


        m.From = New System.Net.Mail.MailAddress(remitente)
        m.To.Add(destino)
        m.Subject = asunto
        'm.Body = "prueba"
        m.IsBodyHtml = True
        m.Priority = System.Net.Mail.MailPriority.Normal

        Dim smtp As New System.Net.Mail.SmtpClient
        If servidor = "" Then servidor = "localhost"
        'smtp.Host = servidor
        smtp.Host = servidor
        If requiereAutenticacion Then
            smtp.Credentials = New System.Net.NetworkCredential(usuario, contrasena)
        End If
        smtp.Send(m)

    End Sub

    Public Shared Function HTMLaString(ByVal url As String) As String
        Dim wr As Net.WebRequest = Net.WebRequest.Create(url)
        Dim wResponse As Net.WebResponse = wr.GetResponse()
        Dim s As IO.Stream = wResponse.GetResponseStream
        Dim sr As New IO.StreamReader(s)
        Dim aux As String
        aux = sr.ReadToEnd
        s.Close()
        Return aux
    End Function
End Class
